#pragma once
#include <iostream>
#include <string>
#include <filesystem>
#include "Color.hpp"

struct html_base
{
    html_base()
    :_if_remove_tag(false),
    _fileno(-1)
    {}

    std::string _url;
    std::string _content;
    std::string _title;
    int _fileno;
    bool _if_remove_tag;
};

struct word_cnt
{
    size_t _title_cnt;
    size_t _content_cnt;
};


struct inverted_base
{
    std::string _word;
    int _fileno;
    size_t _weight;
};


void Change_Dir(const std::string &dirpath)
{
    namespace fs = std::filesystem;
    fs::path tar_path(dirpath);
    if (!fs::is_directory(tar_path))
    {
        // 没有目录, 创建目录
        fs::create_directory(tar_path);
    }
    // 进入目录
    fs::current_path(tar_path);
}

void ProgressBar(int total, int now)
{
    static int len = 100;
    static char bar_body = '=';
    static char bar_end = '>';

    int percent_total = now * len / total;

    std::string bar_str(percent_total, bar_body);
    if (percent_total < total)
        bar_str += bar_end;
    printf(HIDE_CURSOR
               BOLD_WHITE("\r[") CYAN("%-100s") BOLD_WHITE("]")
                   BOLD_MAGENTA("%3ld%%")
                       SHOW_CURSOR,
           bar_str.c_str(), bar_str.size());
}
